package com.ray.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ray.bean.CommonOrderTemplateBean;
import com.ray.service.CommonOrderTemplateService;
import com.ray.service.WarehouseOutPrintTemplateService;
import com.ray.util.RequestUtil;
import com.ray.util.ResponseUtil;

/**
 * 各种模板控制层
 * @author libin
 */
@Controller
@RequestMapping("/printTemplate")
public class PrintDataTemplateController {
	
	@Autowired
	WarehouseOutPrintTemplateService warehouseOutPrintTemplateService;
	
	@Autowired
	CommonOrderTemplateService commonOrderTemplateService;
	
	@RequestMapping("/getPrintDataTemplateByType")
	@ResponseBody
	public Map<String,Object> getPrintDataTemplateByType(HttpServletRequest request){
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		Assert.notNull(map.get("type"),"模板类型为空");
		return ResponseUtil.ResponseResult(warehouseOutPrintTemplateService.getWarehouseOutPrintTemplate(map));
	}
	
	@RequestMapping("/addPrintDataTemplateByType")
	@ResponseBody
	public Map<String,String> addPrintDataTemplateByType(HttpServletRequest request){
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		Assert.notNull(map.get("type"),"模板类型为空");
		Assert.notNull(map.get("loginCompany"),"公司名为空");
		warehouseOutPrintTemplateService.addWarehouseOutPrintTemplate(map);
		return ResponseUtil.ResponseResult("保存模板成功");
	};
	
	@RequestMapping("/getCommonOrderTemplates")
	@ResponseBody
	public Map<String,Object> getCommonOrderTemplates(HttpServletRequest request){
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		List<CommonOrderTemplateBean> templates = commonOrderTemplateService.getTemplates(map);
		return ResponseUtil.ResponseResult(templates);
	}
	
	@RequestMapping("/saveCommonOrderTemplate")
	@ResponseBody
	public Map<String,String> saveCommonOrderTemplate(HttpServletRequest request) {
		Map<String,String> map = RequestUtil.getRequestAllParam(request);
		Assert.notNull(map.get("name"),"模板名称为空");
		Assert.notNull(map.get("type"),"模板类型为空");
		commonOrderTemplateService.saveTemplate(map);
		return ResponseUtil.ResponseResult("保存模板成功");
	}
}
